# coding : utf-8
# @Author : 赐恩明
# vx : 17341788306
import random
import time
import pytest
from configparser import ConfigParser


import pyttsx3


class Run:
    n = 0

    def __init__(self):
        self.cfg = ConfigParser()
        self.con = self.cfg.read(r'./config.ini', encoding='utf-8')
        self.method = self.cfg.get('run', 'METHOD')
        self.reruns = self.cfg.get('run', 'RERUNS')
        self.delay = self.cfg.get('run', 'RERUNS-DELAY')
        self.voice = self.cfg.get('run', 'VOICE')
        self.px = self.cfg.get('self', 'RESOLUTION')
        self.number = self.cfg.get('self', 'NUMBER')
        self.index = self.cfg.get('self', 'INDEX')
        self.greetings = self.cfg.get('run', 'GREETINGS')

    def run(self):
        for _ in range(101):
            print('\r' + _ * '▌' + ' 程序加载中 》》' + f'{_}%', end='')
            while True:
                t = random.uniform(0, 0.1)
                if 0.03 > t or t > 0.09:
                    time.sleep(t)
                    break
        print('\r' + 100 * '▌' + ' 加载完成')
        # time.sleep(2)
        if self.voice.lower() == 'yes':
            pyttsx3.speak('开始投递！')
        pytest.main([f'{self.method}', '--reruns', f'{self.reruns}', "--reruns-delay", f"{self.delay}"])
        if self.voice.lower() == 'yes':
            pyttsx3.speak(f'投递结束！')
        print('Successfully delivered ' + f'{Run.n} resumes。')
